package com.hbwxz.user.controller;

import com.hbwxz.common.response.CommonResponse;
import com.hbwxz.user.pojo.Oauth2ClientRegister;
import com.hbwxz.user.pojo.User;
import com.hbwxz.user.processor.RedisCommonProcessor;
import com.hbwxz.user.service.UserRegisterLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user/register")
public class UserRegisterLoginController {

    @Autowired
    private UserRegisterLoginService userRegisterLoginService;
    @Autowired
    private RedisCommonProcessor redisCommonProcessor;

    @PostMapping("/name-password")
    public CommonResponse newPasswordRegister(@RequestBody User user) {
        return userRegisterLoginService.namePasswordRegister(user);
    }

    @PostMapping("/phone-code")
    public CommonResponse phoneCodeRegister(@RequestParam String phoneNumber, @RequestParam String code) {
        return userRegisterLoginService.phoneCodeRegister(phoneNumber,code);
    }

    @RequestMapping("/gitee")
    public CommonResponse thirdPartGiteeCallback(HttpServletRequest request) {
        return userRegisterLoginService.thirdPartGiteeCallback(request);
    }

    @RequestMapping("/login")
    public CommonResponse login(@RequestParam String username, @RequestParam String password) {
        return userRegisterLoginService.login(username,password);
    }

    @RequestMapping("/third-part-app/request")
    public CommonResponse thirdPartAppRequest(@RequestHeader String personId,@RequestBody Oauth2ClientRegister oauth2ClientRegister) {
        return userRegisterLoginService.thirdPartAppRequest(personId,oauth2ClientRegister);
    }

    @RequestMapping("/third-part-app/request/status")
    public CommonResponse checkThirdPartAppRequestStatus(@RequestHeader String personId) {
        return userRegisterLoginService.checkThirdPartAppRequestStatus(personId);
    }


}
